﻿using Glorysoft.EAP.Core.Entities;
using Glorysoft.EAP.EAPClient.Common;
using Glorysoft.EAP.EAPClient.Model;
using Glorysoft.EAP.EAPClient.View;
using Glorysoft.EAP.EAPClient.ViewModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;

namespace Glorysoft.EAP.EAPClient
{

    /// <summary>
    /// TrackoutLoss.xaml 的交互逻辑
    /// </summary>
    public partial class TrackOutLoss : Window
    {
        public TrackOutLoss()
        {
            InitializeComponent();
            this.DataContext = new TrackOutLossViewModel();
        }
        private void CloseWindowButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        private void FButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (CMessageBox.Show(Consts.GetTranslation("Msg_TrickOUT"), Consts.GetTranslation("Msg_ConfirmInfo"),
                    CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
                {
                    List<Core.Entities.LOSSINFOLIST> LossInfoList = new List<Core.Entities.LOSSINFOLIST>();
                    LossInfoList = TrackOutLossViewModel.loss;
                    List<Core.Entities.LOSSINFOLIST> Loss = new List<Core.Entities.LOSSINFOLIST>();
                    foreach (Core.Entities.LOSSINFOLIST item in LossInfoList)
                    {
                        if (item.PIDLIST.Count > 0)
                        {
                            Core.Entities.LOSSINFOLIST lossinfo = new Core.Entities.LOSSINFOLIST();
                            lossinfo.LOSSCODE = item.LOSSCODE;
                            lossinfo.LOSSCOUNT = item.LOSSCOUNT;
                            lossinfo.LOSSDESC = item.LOSSDESC;
                            lossinfo.PIDLIST = item.PIDLIST;
                            Loss.Add(lossinfo);
                        }
                    }
                    EAPClient eapClient = new EAPClient();
                    eapClient.TrackOutByUser(EquipMendID.Text, Loss);
                    this.Close();
                }
                else
                {
                    //this.Close();
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
        public static List<Core.Entities.LOSSINFOLIST> LinShiList;
        private void FButton_Click1(object sender, RoutedEventArgs e)
        {
            LinShiList = new List<Core.Entities.LOSSINFOLIST>();
            //if (LossSN.count != 0)
            //{
            //    foreach (var item in LossSN.LossInfoList)
            //    {
            //        var loss = new Core.Entities.LOSSINFOLIST();
            //        loss.LOSSCODE = item.LOSSCODE;
            //        loss.LOSSDESC = item.LOSSDESC;
            //        loss.LOSSCOUNT = item.PIDLIST.Count.ToString();
            //        loss.PIDLIST = item.PIDLIST;
            //        LinShiList.Add(loss);
            //    }
            //}
            //else
            //{
            foreach (Model.DefectProduct item in this.DataGridBad.SelectedItems)
            {
                var loss = new Core.Entities.LOSSINFOLIST();
                loss.LOSSCODE = item.Code;
                loss.LOSSDESC = item.Desc;
                loss.LOSSCOUNT = LossSN.count.ToString();
                LinShiList.Add(loss);
            }
            //}
            this.Close();
            LossSN window = new LossSN();
            window.Show();
        }
    }
}
